//
//  ShopLogisticsInfoCell.m
//  BaseFrame
//
//  Created by wingfac on 2017/8/16.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "ShopLogisticsInfoCell.h"
@interface ShopLogisticsInfoCell()
Strong UILabel *titleLabel;
Strong UIImageView *titleImageView;
Strong UIView *bgView;
Strong UIView *lineView;
@end
@implementation ShopLogisticsInfoCell
- (id)initWithCellIdentifier:(NSString *)cellID{
    self = [super initWithCellIdentifier:cellID];
    if (self) {
        
        self.backgroundColor = getColor(@"ebebf1");
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_bgView];
        
        _titleImageView = [UIImageView new];
        //        _titleImageView.contentMode = UIViewContentModeScaleAspectFit;
        _titleImageView.image = [UIImage imageNamed:@"line_nor"];
        [self.contentView addSubview:_titleImageView];
        
        _titleLabel  = [[UILabel alloc]init];
        _titleLabel.font = DEF_FontSize_14;
        _titleLabel.textColor = getColor(textColor);
        _titleLabel.numberOfLines = 0;
        [self.contentView addSubview:_titleLabel];
        
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = getColor(dividerColor);
        [self.contentView addSubview:_lineView];
        
        [self layoutFrame];
    }
    return self;
}

- (void)layoutFrame{
    __weak __typeof(self)weakSelf = self;
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(5 / WIDTH_5S_SCALE);
        make.top.mas_equalTo(0);
        make.width.mas_equalTo( SCREEN_WIDTH -10 / WIDTH_5S_SCALE);
        make.bottom.mas_equalTo(0);
    }];
    
    [self.titleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30 / WIDTH_5S_SCALE);
        make.top.mas_equalTo(8 / WIDTH_5S_SCALE);
        make.width.mas_equalTo(7 / WIDTH_5S_SCALE);
        make.bottom.mas_equalTo(9 / WIDTH_5S_SCALE);
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.titleImageView.mas_right).offset(0 / WIDTH_5S_SCALE);
        make.bottom.mas_equalTo(-0.5);
        make.size.mas_equalTo(CGSizeMake(200 / WIDTH_5S_SCALE, 0.5));
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.titleImageView.mas_right).offset(5 / WIDTH_5S_SCALE);
        make.top.mas_equalTo(0);
        make.width.mas_equalTo(200 / WIDTH_5S_SCALE);
        make.bottom.mas_equalTo(0);
    }];
}

- (void)setModel:(NSDictionary *)model{
    _model = model;
    self.lineView.hidden = NO;
    if (self.indexPath.row == 0) {
        self.titleLabel.textColor = getColor(mainColor);
        self.titleImageView.image = [UIImage imageNamed:@"line_sel"];
        self.lineView.hidden = YES;
    }
    if (model[@"phone"]) {
        self.titleLabel.attributedText = [self getAttributeName:model[@"title"] time:model[@"time"] phone:model[@"phone"]];
    }else{
        self.titleLabel.attributedText = [self getAttributeName:model[@"title"] time:model[@"time"]];
    }
}

- (NSAttributedString *)getAttributeName:(NSString *)name time:(NSString *)time phone:(NSString *)phone{
    NSMutableAttributedString *attStr = [NSMutableAttributedString new];
    NSAttributedString *phoneAtt = [[NSAttributedString alloc]initWithString:phone attributes:@{NSForegroundColorAttributeName:getColor(mainColor)}];
    
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:name]];
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:@"派件员电话:"]];
    
    [attStr appendAttributedString:phoneAtt];
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]];
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:time]];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:6];//调整行间距
    
    [attStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [attStr.mutableString length])];
    
    return attStr;
}

- (NSAttributedString *)getAttributeName:(NSString *)name time:(NSString *)time{
    NSMutableAttributedString *attStr = [NSMutableAttributedString new];
    
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:name]];
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]];
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:time]];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:6];//调整行间距
    
    [attStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [attStr.mutableString length])];
    
    return attStr;
}



@end
